<?php
/**************************************************************************************************
|
| AudioShare - Audio Sharing Script
| http://www.audiosharescript.com
| webmaster@audiosharescript.com
|
|**************************************************************************************************
|
| By using this software you agree that you have read and acknowledged our End-User License 
| Agreement available at http://www.audiosharescript.com/eula.html and to be bound by it.
|
| Copyright (c) 2010 AudioShareScript.com. All rights reserved.
|**************************************************************************************************/

include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];

$playlist_added=0;
if ($_SESSION[USERID] != "" && $_SESSION[USERID] >= 0 && is_numeric($_SESSION[USERID]))
{
	if(isset($_POST["playlist_title"])){
		$playlist_title=mysql_real_escape_string(trim($_POST["playlist_title"]));
		if($playlist_title!=""){
			
			$playlist_title=trim(mysql_real_escape_string($playlist_title));
			## check if playlist with this name already exists...
			$query="select count(*) as count from playlists where playlist_title='".$playlist_title."' and active='1'";
			$executequery = $conn->Execute($query);
			$Isexist=$executequery->fields["count"];
			
			if($Isexist!=0){
				$errorPlaylist="Playlist not created as playlist with this title already exixts.";
			}
			else{
				$query = "INSERT INTO playlists SET playlist_title='".$playlist_title."',USERID='".mysql_real_escape_string($_SESSION[USERID])."', date_added='".date("Y-m-d")."'";
				$conn->execute($query);	
				$playlist_added=1;
			}
		}
		else{
			$errorPlaylist="Playlist title cannot be empty.";
		}
	}
	/*else{
			$errorPlaylist="Playlist title cannot be empty.";
		}*/
}
else
{
	header("Location:$config[baseurl]/login.php");exit;
}

STemplate::assign('title',$playlist_title);
STemplate::assign('playlist_added',$playlist_added);

STemplate::assign('pagetitle',"$lang[797]");

//TEMPLATES BEGIN
STemplate::assign('errorPlaylist',$errorPlaylist);
STemplate::display('header.tpl');
STemplate::display('create_playlist.tpl');
STemplate::display('footer.tpl');
//TEMPLATES END
?>